package com.linln.modules.system.repository;

import com.linln.modules.system.domain.Evaluate;
import com.linln.modules.system.domain.Msg;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface EvaluateRepository extends JpaRepository<Evaluate, Long>, JpaSpecificationExecutor<Evaluate> {
    //统计符合公司条件的记录数量（公司ID为空时统计所有）
    @Query("SELECT e.score, COUNT(e) FROM Evaluate e WHERE (:companyId IS NULL OR e.companyId = :companyId) GROUP BY e.score")
    List<Object[]> countByCompany(@Param("companyId") Long companyId);
}
